package com.nuedu.corejava.ch9;

import java.util.Scanner;

public class StringClass {
	public static void main(String[] args) {
		String s = new String("abc");
		//java的字符串对子昂时不可以修改的，每次重新修改字符串都会分配新的内存空间
		//String类的修改性能很低
		s = new String("asdf asd fa");
		
		
		//带缓冲的字符串类 - StringBuffer多线程安全的类 StringBuilder是线程不安全的；
		//面试题：简述String 、StringBuffer 和 StringBuilder的异同；
		StringBuilder buffer = new StringBuilder();
		buffer.append(false);
		buffer.append("hello");
		buffer.insert(5,"ABCDEF");
		
		
		int cap =  buffer.capacity();//字符串缓冲的容量
		int len = buffer.length();//数据长度
		
		System.out.println(cap+", "+len);
		System.out.println(buffer);
		System.out.println("=====================");
		
		
		buffer.insert(0, "A");
		 cap =  buffer.capacity();//字符串缓冲的容量
		 len = buffer.length();//数据长度
		System.out.println(cap+", "+len);
		System.out.println(buffer);
		System.out.println("=====================");
		
		//buffer.deleteCharAt(0);
	//	buffer.delete(0,12);
		buffer.trimToSize();//释放没有使用的空间容量
		
		
		 cap =  buffer.capacity();//字符串缓冲的容量
		 len = buffer.length();//数据长度
		System.out.println(cap+", "+len);
		System.out.println(buffer);
		System.out.println("=====================");
		buffer.replace(0, 4, "A");
		System.out.println(buffer);
		System.out.println("=====================");
		//输入一个手机号码，将中间四位使用星号替代。
		System.out.println("请输入一个11位数的号码");
		Scanner syScanner = new Scanner(System.in);
		String p = syScanner.nextLine();
		StringBuffer phone = new StringBuffer(p);
		phone.replace(3, 7, "****");
		
		System.out.println(phone);

				
	}
}
